<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jq/jquery1.9/jquery-1.9.0.js"></script>
    <script>
        $(function () {
            $("input:eq(0)").click(function () {
                $("div a:first-child").css("background", "red");
            });
            $("input:eq(1)").click(function () {
                $("div a:last-child").css("background", "red");
            });
            $("input:eq(2)").click(function () {
                /*   nth‐child()参数：
                      1.number 1 从1开始
                      2.odd/even 奇数个/偶数个
                      3.表达式 2n+2 n从0算起 */
                $("div a:nth-child(2)").css("background","red");
                // $("div a:nth-child(2n+1)").css("background", "red");
                // $("div a:nth-child(even)").css("background", "red");
            });
            $("input:eq(3)").click(function () {
                $("div a:nth-child(even)").css("background","red");
            });

            $("input:eq(4)").click(function () {

                $("div a:only-child").css("background", "yellow");
            });

           

        });
    </script>
</head>

<body>
    <input type="button" value="选择每个div元素下的第一个a元素">
    <input type="button" value="选择每个div元素下的最后一个a元素">
    <input type="button" value="选择每个div元素下的第二个a元素">
    <input type="button" value="选择每个div元素下的偶数a元素">
    <input type="button" value="作为其父元素唯一的子元素的a元素">
    <div>
        <a href="">a01</a>
        <a href="">a02</a>
        <a href="">a03</a>
    </div>
    <div>
        <a href="">a01</a>
        <a href="">a02</a>
        <a href="">a03</a>
    </div>
    <p>
        <a href="">a01</a>
        <a href="">a02</a>
        <a href="">a03</a>
    </p>
    <div>
        <a href="">01</a>
    </div>
</body>

</html>